package org.sbbs.app.security.webapp.action;

import org.sbbs.app.security.model.Menu;
import org.sbbs.app.security.service.MenuManager;
import org.sbbs.base.pager.IPager;
import org.sbbs.base.pager.impl.JqgridPagerImpl;
import org.sbbs.base.searcher.SearchFilter;
import org.sbbs.base.searcher.SearchFilterBuilder;
import org.sbbs.base.webapp.action.BaseJqgridPagedAction;

public class MenuPagedAction
    extends BaseJqgridPagedAction {
    /**
     *
     */
    private static final long serialVersionUID = 7495156251577674342L;

    @Override
    public Class getSearchEntityClazz() {
        return Menu.class;
    }

    @Override
    public int getSearchFilterType() {
        return SearchFilterBuilder.PROPERTY_FILTER;
    }

    private MenuManager menuManager;

    public MenuManager getMenuManager() {
        return menuManager;
    }

    public void setMenuManager( MenuManager menuManager ) {
        this.menuManager = menuManager;
    }

    @Override
    public String gridPageList() {
        try {
            IPager pager = new JqgridPagerImpl( getRequest() );
            SearchFilter sf = SearchFilterBuilder.buildSearchFilter( getRequest(), this.getSearchFilterType());
            pager = this.menuManager.pagedQuery(this.getSearchEntityClazz(), pager, sf );

            this.pageList = pager.getList();
            records = pager.getTotalNumberOfRows();
            total = pager.getTotalNumberOfPages();
            page = pager.getPageNumber();

        }
        catch ( Exception e ) {
            log.error( "GridList Error", e );
        }
        return SUCCESS;
    }
}
